﻿<!--*********************************************************************

   Extended WPF Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. The commercial version of Extended WPF Toolkit also includes
   priority technical support, commercial updates, and many additional 
   useful WPF controls if you license Xceed Business Suite for WPF.

   Visit http://xceed.com and follow @datagrid on Twitter.

  ********************************************************************-->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Twi.COMMON.WPF.CtlExtended"
                    xmlns:conv="clr-namespace:Twi.COMMON.WPF.CtlExtended.Mag.Converters">

   <!-- =============================================================================== -->
   <!-- Magnifier                                                                       -->
   <!-- =============================================================================== -->

   <conv:RadiusConverter x:Key="RadiusConverter" />
   <conv:BorderThicknessToStrokeThicknessConverter x:Key="BorderThicknessToStrokeThicknessConverter" />

   <ControlTemplate x:Key="CircleTemplate" TargetType="{x:Type local:Magnifier}">
      <Grid>
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="{Binding Path=Radius, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource RadiusConverter}}" />
         </Grid.ColumnDefinitions>
         <Grid.RowDefinitions>
            <RowDefinition Height="{Binding Path=Radius, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource RadiusConverter}}" />
         </Grid.RowDefinitions>
         <Ellipse Width="{Binding Path=FrameWidth, RelativeSource={RelativeSource TemplatedParent}}" 
                  Height="{Binding Path=FrameHeight, RelativeSource={RelativeSource TemplatedParent}}" 
                  Fill="{TemplateBinding Background}" />
         <Ellipse Stroke="{Binding Path=BorderBrush, RelativeSource={RelativeSource TemplatedParent}}" 
                  StrokeThickness="{Binding Path=BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BorderThicknessToStrokeThicknessConverter}}">
            <Ellipse.Fill>
               <VisualBrush Viewbox="{Binding Path=ViewBox, RelativeSource={RelativeSource TemplatedParent}}" 
                            ViewboxUnits="Absolute"
                            Visual="{Binding Path=Target, RelativeSource={RelativeSource TemplatedParent}}" />
            </Ellipse.Fill>
         </Ellipse>
      </Grid>
   </ControlTemplate>

   <ControlTemplate x:Key="RectangleTemplate" TargetType="{x:Type local:Magnifier}">
      <Canvas Background="{TemplateBinding Background}"
              Width="{Binding Path=FrameWidth, RelativeSource={RelativeSource TemplatedParent}}" 
              Height="{Binding Path=FrameHeight, RelativeSource={RelativeSource TemplatedParent}}">
         <Rectangle Width="{Binding Path=Width, RelativeSource={RelativeSource TemplatedParent}}" 
                    Height="{Binding Path=Height, RelativeSource={RelativeSource TemplatedParent}}"
                    Stroke="{Binding Path=BorderBrush, RelativeSource={RelativeSource TemplatedParent}}"
                    StrokeThickness="{Binding Path=BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BorderThicknessToStrokeThicknessConverter}}">
            <Rectangle.Fill>
               <VisualBrush Viewbox="{Binding Path=ViewBox, RelativeSource={RelativeSource TemplatedParent}}"
                            ViewboxUnits="Absolute"
                            Visual="{Binding Path=Target, RelativeSource={RelativeSource TemplatedParent}}" />
            </Rectangle.Fill>
         </Rectangle>
      </Canvas>
   </ControlTemplate>

   <Style TargetType="{x:Type local:Magnifier}">
      <Setter Property="IsHitTestVisible" Value="False" />
      <Style.Triggers>
         <Trigger Property="FrameType" Value="Circle">
            <Setter Property="Template" Value="{StaticResource CircleTemplate}" />
         </Trigger>
         <Trigger Property="FrameType" Value="Rectangle">
            <Setter Property="Template" Value="{StaticResource RectangleTemplate}" />
         </Trigger>
      </Style.Triggers>
   </Style>

</ResourceDictionary>